package com.openweixin.sheknows.dao.impl;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.openweixin.sheknows.dao.UserNewAnswerDao;
import com.openweixin.sheknows.domain.UserNewAnswer;
import com.openweixin.sheknows.domain.UserNewScore;
@Repository
public class UserNewAnswerDaoImpl extends BaseDaoImpl<UserNewAnswer, Integer> implements UserNewAnswerDao {

	@Override
	public Long getNewAnswerCountByUid(Integer uid) {
		String hql = "select count(una.answeruid) from UserNewAnswer una where una.pk.user.uid = ?";
		return (Long)getSession().createQuery(hql).setInteger(0, uid).uniqueResult();
	}

	@Override
	public int deleteByUid(Integer uid) {
		String hql = "delete from UserNewAnswer where pk.user.uid = ?";
		return getSession().createQuery(hql).setInteger(0, uid).executeUpdate();
	} 
	
	public List<UserNewScore> getNewScoreByUidAndQid(Integer uid, Integer qid){
		String hql = "from UserNewAnswer una where pk.user.uid = ? and pk.question.uid = ? ";
		return (List<UserNewScore>) getSession().createQuery(hql)
				.setInteger(0, uid).setInteger(0, qid).list();
	}
}
